package com.xty.itgroup.tech05tytex.Controller;

import com.xty.itgroup.tech05tytex.Databean.Bean03Contract;
import com.xty.itgroup.tech05tytex.Logic.Logic03Contract;
import com.xty.itgroup.tech05tytex.Util.Result;
import com.xty.itgroup.tech05tytex.Util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "ContractController", tags = "合同相关接口")
@RequestMapping("/contract")
@RestController
public class ContractController {
    @Autowired
    private Logic03Contract contract;

    @ApiOperation(value = "查询合同", notes = "根据业务员，客户，时间模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_name", value = "业务员", required = false, dataType = "String"),
            @ApiImplicitParam(name = "customer_name", value = "客户", required = false, dataType = "String"),
            @ApiImplicitParam(name = "start_time", value = "开始时间", required = false, dataType = "String"),
            @ApiImplicitParam(name = "end_time", value = "结束时间", required = false, dataType = "String"),
            @ApiImplicitParam(name = "is_back", value = "是否回签", required = true, dataType = "int"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "int")
    })
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listContract(String user_name, String customer_name, String start_time, String end_time, int is_back, int status) {
        return ResultUtil.success(contract.listContract(user_name, customer_name, start_time, end_time, is_back, status));
    }
    @ApiOperation(value = "添加合同", notes = "添加合同和详情")//716559
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result addContract(@RequestBody Bean03Contract bc) {
        contract.addContract(bc);
        return ResultUtil.success();
    }
    @ApiOperation(value = "修改合同", notes = "修改合同和详情")//716559
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public Result modifyContract(@RequestBody Bean03Contract bc) {
        contract.modifyContract(bc);
        return ResultUtil.success();
    }
    @ApiOperation(value = "合同确认", notes = "修改合同状态 草稿->新建")//716559

    @ApiImplicitParams({
            @ApiImplicitParam(name = "tex_id", value = "主键", required = true, dataType = "int", example = "1"),
            @ApiImplicitParam(name = "status", value = "结束时间", required = false, dataType = "int",example = "1")
    })
    @RequestMapping(value = "/status", method = RequestMethod.POST)
    public Result statusSet(int tex_id,int status) {
        contract.statusSet(tex_id, status);
        return ResultUtil.success();
    }
    @RequestMapping(value = "/back", method = RequestMethod.POST)
    public Result backDateSet(int tex_id,int status, String contract_back_date) {
        contract.backDateSet(tex_id, status, contract_back_date);
        return ResultUtil.success();
    }
    @ApiOperation(value = "删除合同", notes = "根据主键作废合同")//334038
    @ApiImplicitParam(name = "tex_id", value = "主键", required = true, dataType = "String", example = "1")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result deleteContract(int tex_id) {
        contract.deleteContract(tex_id);
        return ResultUtil.success();
    }
    @ApiOperation(value = "获取合同详情", notes = "根据主键获取合同详情")
    @ApiImplicitParam(name = "tex_id", value = "主键", required = true, dataType = "String", example = "1")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Result getContract(int tex_id) {
        return ResultUtil.success(contract.getContract(tex_id));
    }

}
